<?php
	include_once '../models/Model.php';
	$model=new Model();
	session_start();
	$userId=$_SESSION['userId'];
	$unauthorizedTime=$model->showUserPenalty($item,date('Y-m',$lastMonth));
			//var_dump($unauthorizedTime);
	$fee=0;		
	if($unauthorizedTime!=null)	
		foreach($unauthorizedTime as $time)
			$fee+=100000*ceil($time/30);
	$month=date('Y-m');		
	$order=$model->searchOrderByUserId($month,$userId);
	//var_dump($order);die;
	if($order!=null)
		foreach ($order as $element)
		 {
				$roomId=$element->getRoomId();
				$room=$model->getRoomById($roomId);
				$roomCost=$room->getRoomCost();
			
				//get book time 
				$startTime=$element->getOrderStartTime();
				$endTime=$element->getOrderEndTime();
				$bookTime=(strtotime($endTime)-strtotime($startTime))/60;
					
				//get order status
				$orderStatus=$element->getOrderStatus();
				//booked status
				$orderFee=$model->getOrderFee();
				$cancelFee=$model->getCancelFee();
				if($orderStatus==1)
						$fee+=$orderFee;
				//canceled status
				else if($orderStatus==2)
						$fee+=$cancelFee;
				//used status				
				else if($orderStatus==3)
						$fee+=$bookTime/30*$roomCost; 
		 }
	$user=$model->searchUserById($userId);	 
	//var_dump($user);die;
	//echo $userId.":".$fee;die;	 
	include_once '../view/user/view_fee.php';